package com.longrise.android.byjk.plugins.vip.integralexchange;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.longrise.android.byjk.R;
import com.longrise.common.base.BaseActivity;
import com.longrise.common.utils.AppUtil;

/**
 * Created by callxkj on 2017/7/22.
 * 积分兑换页面改版 增加展业秀勋章
 */

public class IntegralExchange2Activity extends BaseActivity {
    private Toolbar mToolbar;
    private TabLayout mTb;
    private ViewPager mVp;
    public static final String PAGE_FROM_FLAG = "page_from_flag";
    public static final int PAGE_FROM_NOMARL = 1; //来自一般页面
    public static final int PAGE_FROM_MYMEDAL = 2; //来自我的勋章
    public int mPageFrom = PAGE_FROM_NOMARL; //默认是来自一般页面

    @Override
    public int getContentViewId(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_integralexchange2;
    }

    @Override
    public void initView() {
        mToolbar = (Toolbar) findViewById(R.id.byjk_toolbar);
        setTitle(AppUtil.getString(R.string.dailysign_jfdh));
        setSupportActionBar(mToolbar);
        mTb = (TabLayout) findViewById(R.id.integral_exchange2_tb);
        mVp = (ViewPager) findViewById(R.id.integral_exchange2_vp);
        getIntentData();
        initAdapter();
        initEvent();
    }

    private void getIntentData() {
        Intent intent = getIntent();
        int pagefrom = intent.getIntExtra(PAGE_FROM_FLAG, PAGE_FROM_NOMARL);
        if (PAGE_FROM_NOMARL == pagefrom) {
            mPageFrom = PAGE_FROM_NOMARL;
        } else {
            mPageFrom = PAGE_FROM_MYMEDAL;
        }
    }


    private void initAdapter() {
        IntegralExchange2Adapter adapter = new IntegralExchange2Adapter(getSupportFragmentManager());
        mVp.setAdapter(adapter);
        mTb.setupWithViewPager(mVp);
        if(mPageFrom == PAGE_FROM_NOMARL){
            mVp.setCurrentItem(0);
        }else{
            mVp.setCurrentItem(1);
        }
    }

    private void initEvent() {
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


}
